package app.domain;

import lombok.*;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.stereotype.Component;

import javax.persistence.*;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

@Entity
@Table(name = "role")
@Getter
@Setter
@ToString
@AllArgsConstructor
@NoArgsConstructor
@Component
public class Role implements Serializable {
    //id生成策略
    @Id
    @GenericGenerator(name = "pk", strategy = "increment")
    @GeneratedValue(generator = "pk")
    @Column(name = "id")
    private Integer id;
    @Column(name = "name")
    private String name;

    //多对多关系 (User vs Role)
    @OneToMany(cascade = CascadeType.ALL,fetch=FetchType.EAGER)
    @Fetch(FetchMode.SELECT)
    //中间表名,当前对象id在中间表的列名,关联的另一个表在中间表的列名
    @JoinTable(name = "rj", joinColumns = {@JoinColumn(name = "roleid")}, inverseJoinColumns = {@JoinColumn(name = "jurisdictionid")})
    private Set<Jurisdiction> jurisdictions;
}
